<?php
namespace Api\Controller;
use Think\Controller;

class InstoreController extends BaseController {

   private $m = NULL;
   private $md = NULL;
   private $navName = '订单管理';


   public function _initialize(){
   		parent::_initialize();
		//$this->m = M('shop_notice');
		
		
		
   }
 /**  店内消费 liuq
 *
 */	
   
  
   
    public  function  in_store(){
     
                $shop_no = I('shop_no');
                $shop_mid = M('shop')->where('id="'.$shop_no.'" AND buss_status =2 AND (shop_level_two = 18 OR  shop_level_two = 19) ')->getField('mid');
              
                if( $shop_mid ){
                    $mid = $shop_mid;   
                    $data3['mid'] = $mid;
                    
                }else{
                    returnmemberError("1", "店铺号不存在或已被禁用");exit;
                }
                
                
                $in_type = M('shop')->where('mid="'.$mid.'"')->getField('shop_level_two');
                
                if( $in_type == 18 ){
                        //左侧类别信息
                    //此时时间戳
                    $now_time = time(); 
                    //当天凌晨
                    $day_break = strtotime(date('Y-m-d'));  
                    //本月第一天时间戳
                    $month_first_day = mktime(0,0,0,date('m'),1,date('Y')); 
                    //本年第一天时间戳
                    $year_first_day = mktime(0,0,0,1,1,date("Y",time())); 

                     $data = M('shop_product')->where('mid="'.$mid.'"')->select();
                     foreach ( $data as $key => $item ){
                       $data[$key]['pic_path'] = $item['pic_path']?__VUPLOAD__.'pro/'.$item['pic_path']:""; //产品头像  
                       $data[$key]['month_sale_num'] = M('shop_product_order_pro')->where('pro_id="'.$item['id'].'" AND add_time >="'.$month_first_day .'" AND add_time <="'.$now_time .'"')->count();
                     }


                     $info = M('shop_product_type')->where('mid="'.$mid.'"')->select();
                     foreach( $info as $key => $item ){
                            $data2[$key]['type_id'] = $item['id'];
                            $data2[$key]['type_name'] = $item['type_name'];
                     }


                       $attitude = M('shop_evaluate')->where('mid="'.$mid.'"')->sum('attitude_star'); 
                       $speed = M('shop_evaluate')->where('mid="'.$mid.'"')->sum('speed_star'); 
                       $taste = M('shop_evaluate')->where('mid="'.$mid.'"')->sum('taste_star'); 
                       $evaluate_times = M('shop_evaluate')->where('mid="'.$mid.'"')->count();
                       $comment_star = round(( $attitude  + $speed + $taste )/( $evaluate_times*3 ));  


                       if(  $comment_star == 1 ){
                          $data3['comment_star_value'] = __VUPLOAD__.'evaluate/'."1star.png";
                       }elseif(   $comment_star == 2  ){
                          $data3['comment_star_value'] = __VUPLOAD__.'evaluate/'."2star.png";
                       }elseif(   $comment_star == 3  ){
                          $data3['comment_star_value'] = __VUPLOAD__.'evaluate/'."3star.png";
                       }elseif(   $comment_star == 4  ){
                          $data3['comment_star_value'] = __VUPLOAD__.'evaluate/'."4star.png";
                       }elseif(   $comment_star == 5  ){
                          $data3['comment_star_value'] = __VUPLOAD__.'evaluate/'."5star.png";
                       }else{
                           $data3['comment_star_value'] = __VUPLOAD__.'evaluate/'."6star.png";
                       }


                       $dataInfo =  M('shop')->where('mid="'.$mid.'"')->find();
                       $data3['comment_star_num'] = $comment_star;
                       $data3['shop_name'] = $dataInfo['shop_name'];
                       $data3['shop_intro'] = $dataInfo['shop_intro'];    
                       $data3['address'] = M('shop_detail')->where('s_id="'.$dataInfo['id'].'"')->getField('address');
                       $data3['telephone'] = M('shop_detail')->where('s_id="'.$dataInfo['id'].'"')->getField('telephone');
                       $data3['class_name'] = M('shop_product_class')->where('id="'.$dataInfo['shop_level_three'].'"')->getField('class_name');
                       $data3['min_delivery_fee'] = M('shop_detail')->where('s_id="'.$dataInfo['id'].'"')->getField('min_delivery_fee');

                       $data3['shop_heapic'] = M('shop_detail')->where("s_id=".$dataInfo['id'])->getField('shop_heapic')?__VUPLOAD__.'shop_heapic/'.M('shop_detail')->where("s_id=".$dataInfo['id'])->getField('shop_heapic'):""; //店铺头像
                       $data3['shop_toppics']  =  M('shop_detail')->where("s_id=".$dataInfo['id'])->getField('shop_toppics')?__VUPLOAD__.'shop_toppics/'.M('shop_detail')->where("s_id=".$dataInfo['id'])->getField('shop_toppics'):"";

                     //  returnApiData2('0','成功',$data, $data2,$data3);exit;

                    }
                
                if( $in_type ==  19){
                    
                        $shop_id = M('shop')->where('mid="'.$mid.'"')->getField('id');
                        $dataInfo = M('shop_detail')->where('s_id="'.$shop_id.'"')->find();
                        $data['mid'] = $mid;
                        $data['shop_toppics']  =  $dataInfo['shop_toppics']?__VUPLOAD__.'shop_toppics/'.$dataInfo['shop_toppics']:"";
                        $data['shop_heapic']  =  $dataInfo['shop_heapic']?__VUPLOAD__.'shop_heapic/'.$dataInfo['shop_heapic']:"";
                        $data['shop_name'] = M('shop')->where('mid="'.$mid.'"')->getField('shop_name');
                        $shop_level_one = M('shop')->where('mid="'.$mid.'"')->getField('shop_level_one');
                        $data['class_name'] =  M('shop_product_class')->where('id="'.$shop_level_one.'"')->getField('class_name');
                        $data['shop_intro'] = M('shop')->where('mid="'.$mid.'"')->getField('shop_intro');    
                        $data['address'] = M('shop_detail')->where('s_id="'.$shop_id.'"')->getField('address'); 
                        $data['shop_intropics'] = $dataInfo['shop_intropics'];  
                        $data['per_consumption'] = $dataInfo['per_consumption'];   
                        $data['telephone'] = M('shop_detail')->where('s_id="'.$shop_id.'"')->getField('telephone');  
                       // $data['class_name'] = M('shop_product_class')->where('id="'.$dataInfo['shop_level_three'].'"')->getField('class_name');

                        $attitude = M('shop_evaluate')->where('mid="'.$mid.'"')->sum('attitude_star'); 
                        $speed = M('shop_evaluate')->where('mid="'.$mid.'"')->sum('speed_star'); 
                        $taste = M('shop_evaluate')->where('mid="'.$mid.'"')->sum('taste_star'); 
                        $evaluate_times = M('shop_evaluate')->where('mid="'.$mid.'"')->count();
                        $comment_star = round(( $attitude  + $speed + $taste )/( $evaluate_times*3 ));  
                        $data['comment_star_num'] = $comment_star;

                         if(  $comment_star == 1 ){
                            $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."1star.png";
                         }elseif(   $comment_star == 2  ){
                            $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."2star.png";
                         }elseif(   $comment_star == 3  ){
                            $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."3star.png";
                         }elseif(   $comment_star == 4  ){
                            $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."4star.png";
                         }elseif(   $comment_star == 5  ){
                            $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."5star.png";
                         }else{
                            $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."6star.png";
                         }

                    
                }
                                
                     returnApiData4('0','成功',$data, $data2,$data3,$in_type);exit;	

    }

    
    
    public   function   in_store_evaluate(){
           $mid = I('mid');  //下方循环评论
           $data = M('shop_evaluate')->where('mid="'.$mid.'"')->order('add_time desc')->select();
         
           foreach (  $data as $key => $item ){
                     
                   $every_star_total = $data[$key]['attitude_star'] + $data[$key]['speed_star'] +$data[$key]['taste_star'];
                   $data[$key]['comment_star'] = round( $every_star_total/3 );
               
                   if( $data[$key]['comment_star'] == 1 ){
                      $data[$key]['comment_star_value'] = __VUPLOAD__.'evaluate/'."1star.jpg";
                   }elseif(  $data[$key]['comment_star'] == 2  ){
                      $data[$key]['comment_star_value'] = __VUPLOAD__.'evaluate/'."2star.jpg";
                   }elseif(  $data[$key]['comment_star'] == 3  ){
                      $data[$key]['comment_star_value'] = __VUPLOAD__.'evaluate/'."3star.jpg";
                   }elseif(  $data[$key]['comment_star'] == 4  ){
                      $data[$key]['comment_star_value'] = __VUPLOAD__.'evaluate/'."4star.jpg";
                   }elseif(  $data[$key]['comment_star'] == 5  ){
                      $data[$key]['comment_star_value'] = __VUPLOAD__.'evaluate/'."5star.jpg";
                   }else{
                       $data[$key]['comment_star_value'] = __VUPLOAD__.'evaluate/'."null.jpg";
                   }
                   
                   $phone_num = M('customer')->where('cid="'.$item['cid'].'"')->getField('phone'); 
                   $data[$key]['phone'] = substr_replace($phone_num,'****',3,4);
                   $data[$key]['heapic'] = M('customer')->where('cid="'.$item['cid'].'"')->getField('heapic')?__VUPLOAD__.'heapic/'.M('customer')->where('cid="'.$item['cid'].'"')->getField('heapic'):""; //用户头像
                   //$data[$key]['evaluate_pics'] = __VUPLOAD__.'evaluate_pics/'.$item['evaluate_pics']; //evaluate_pics
       
                  $evaluate_pics = $item['evaluate_pics']; //evaluate_pics
                  $datapics = explode("|", $evaluate_pics);
                  $data[$key]["evaluate_pics"]=$datapics;
                  foreach ($data[$key]["evaluate_pics"] as $key1 => $value) {
                    $data[$key]["evaluate_pics"][$key1]=__VUPLOAD__.'evaluate_pics/'.$value;
                  }

               }
           
                   // 顶部总的三个评价
                            $attitude_star_total =  M('shop_evaluate')->where('mid="'.$mid.'"')->sum('attitude_star'); 
                              $attitude_star_total_count = M('shop_evaluate')->where('mid="'.$mid.'"')->count();
                                $attitude_star_num = round(   $attitude_star_total / $attitude_star_total_count ); 
                                  if(  $attitude_star_num  == 1 ){
                                     $data1['attitude_star_value'] = __VUPLOAD__.'evaluate/'."1star.jpg";
                                   }elseif(   $attitude_star_num  == 2  ){
                                     $data1['attitude_star_value'] = __VUPLOAD__.'evaluate/'."2star.jpg";
                                   }elseif(   $attitude_star_num  == 3  ){
                                     $data1['attitude_star_value'] = __VUPLOAD__.'evaluate/'."3star.jpg";
                                   }elseif(  $attitude_star_num  == 4  ){
                                     $data1['attitude_star_value'] = __VUPLOAD__.'evaluate/'."4star.jpg";
                                   }elseif(   $attitude_star_num  == 5  ){
                                    $data1['attitude_star_value'] = __VUPLOAD__.'evaluate/'."5star.jpg";
                                   }else{
                                    $data1['attitude_star_value'] = __VUPLOAD__.'evaluate/'."null.jpg";
                                   }
                      
                                $speed_star_total =  M('shop_evaluate')->where('mid="'.$mid.'"')->sum('speed_star'); 
                                  $speed_star_total_count = M('shop_evaluate')->where('mid="'.$mid.'"')->count();
                                    $speed_star_num  = round(   $speed_star_total / $speed_star_total_count );
                                   if(  $speed_star_num  == 1 ){
                                     $data1['speed_star_value'] = __VUPLOAD__.'evaluate/'."1star.jpg";
                                   }elseif(  $speed_star_num == 2  ){
                                     $data1['speed_star_value'] = __VUPLOAD__.'evaluate/'."2star.jpg";
                                   }elseif(   $speed_star_num == 3  ){
                                     $data1['speed_star_value'] = __VUPLOAD__.'evaluate/'."3star.jpg";
                                   }elseif(  $speed_star_num == 4  ){
                                     $data1['speed_star_value'] = __VUPLOAD__.'evaluate/'."4star.jpg";
                                   }elseif(   $speed_star_num  == 5  ){
                                    $data1['speed_star_value'] = __VUPLOAD__.'evaluate/'."5star.jpg";
                                   }else{
                                    $data1['speed_star_value'] = __VUPLOAD__.'evaluate/'."null.jpg";
                                   } 
                             
                               $taste_star_total =  M('shop_evaluate')->where('mid="'.$mid.'"')->sum('taste_star'); 
                                 $taste_star_total_count = M('shop_evaluate')->where('mid="'.$mid.'"')->count();
                                    $taste_star_num = round(   $taste_star_total / $taste_star_total_count );
                                     if(  $taste_star_num  == 1 ){
                                        $data1['taste_star_value'] = __VUPLOAD__.'evaluate/'."1star.jpg";
                                      }elseif(  $taste_star_num == 2  ){
                                        $data1['taste_star_value'] = __VUPLOAD__.'evaluate/'."2star.jpg";
                                      }elseif(   $taste_star_num == 3  ){
                                        $data1['taste_star_value'] = __VUPLOAD__.'evaluate/'."3star.jpg";
                                      }elseif(  $taste_star_num == 4  ){
                                        $data1['taste_star_value'] = __VUPLOAD__.'evaluate/'."4star.jpg";
                                      }elseif(   $taste_star_num  == 5  ){
                                       $data1['taste_star_value'] = __VUPLOAD__.'evaluate/'."5star.jpg";
                                      }else{
                                       $data1['taste_star_value'] = __VUPLOAD__.'evaluate/'."null.jpg";
                                      } 
                               
                       //  print_r($data);exit;
                         returnApiData2('0','成功',$data, $data1,$data3);exit;	
        
        
        
        
    }
    
   
  
   public function in_store2(){
                $shop_no = I('shop_no');
                $shop_mid = M('shop')->where('id="'.$shop_no.'" AND buss_status =2')->getField('mid');
                if( $shop_mid ){
                    $mid = $shop_mid;   
                }else{
                    returnmemberError("1", "店铺号不存在或已被禁用");exit;
                }
            
                //左侧类别信息
                //此时时间戳
	        $now_time = time(); 
                //当天凌晨
                $day_break = strtotime(date('Y-m-d'));  
                //本月第一天时间戳
                $month_first_day = mktime(0,0,0,date('m'),1,date('Y')); 
                //本年第一天时间戳
                $year_first_day = mktime(0,0,0,1,1,date("Y",time())); 
               
                $data = M('shop_product')->where('mid="'.$mid.'"')->select();
                foreach ( $data as $key => $item ){
                   $data[$key]['pic_path'] = $item['pic_path']?__VUPLOAD__.'pro/'.$item['pic_path']:""; //产品头像  
                   $data[$key]['month_sale_num'] = M('shop_product_order_pro')->where('pro_id="'.$item['id'].'" AND add_time >="'.$month_first_day .'" AND add_time <="'.$now_time .'"')->count();
                }
               
               
               $info = M('shop_product_type')->where('mid="'.$mid.'"')->select();
               foreach( $info as $key => $item ){
                        $data2[$key]['type_id'] = $item['id'];
                        $data2[$key]['type_name'] = $item['type_name'];
               }
              
            
                   $attitude = M('shop_evaluate')->where('mid="'.$mid.'"')->sum('attitude_star'); 
                   $speed = M('shop_evaluate')->where('mid="'.$mid.'"')->sum('speed_star'); 
                   $taste = M('shop_evaluate')->where('mid="'.$mid.'"')->sum('taste_star'); 
                   $evaluate_times = M('shop_evaluate')->where('mid="'.$mid.'"')->count();
                   $comment_star = round(( $attitude  + $speed + $taste )/( $evaluate_times*3 ));  
                   
                    
                   if(  $comment_star == 1 ){
                      $data3['comment_star_value'] = __VUPLOAD__.'evaluate/'."1star.png";
                   }elseif(   $comment_star == 2  ){
                      $data3['comment_star_value'] = __VUPLOAD__.'evaluate/'."2star.png";
                   }elseif(   $comment_star == 3  ){
                      $data3['comment_star_value'] = __VUPLOAD__.'evaluate/'."3star.png";
                   }elseif(   $comment_star == 4  ){
                      $data3['comment_star_value'] = __VUPLOAD__.'evaluate/'."4star.png";
                   }elseif(   $comment_star == 5  ){
                      $data3['comment_star_value'] = __VUPLOAD__.'evaluate/'."5star.png";
                   }else{
                       $data3['comment_star_value'] = __VUPLOAD__.'evaluate/'."6star.png";
                   }
                   
                   
                   $dataInfo =  M('shop')->where('mid="'.$mid.'"')->find();
                   $data3['comment_star_num'] = $comment_star;
                   $data3['shop_name'] = $dataInfo['shop_name'];
                   $data3['shop_intro'] = $dataInfo['shop_intro'];    
                   $data3['address'] = M('shop_detail')->where('s_id="'.$dataInfo['id'].'"')->getField('address');
                   $data3['telephone'] = M('shop_detail')->where('s_id="'.$dataInfo['id'].'"')->getField('telephone');
                   $data3['class_name'] = M('shop_product_class')->where('id="'.$dataInfo['shop_level_three'].'"')->getField('class_name');
                   $data3['min_delivery_fee'] = M('shop_detail')->where('s_id="'.$dataInfo['id'].'"')->getField('min_delivery_fee');
                       
                   $data3['shop_heapic'] = $this->md->where("s_id=".$dataInfo['id'])->getField('shop_heapic')?__VUPLOAD__.'shop_heapic/'.$this->md->where("s_id=".$dataInfo['id'])->getField('shop_heapic'):""; //店铺头像
                   $data3['shop_toppics']  =  $this->md->where("s_id=".$dataInfo['id'])->getField('shop_toppics')?__VUPLOAD__.'shop_toppics/'.$this->md->where("s_id=".$dataInfo['id'])->getField('shop_toppics'):"";
                   
                   returnApiData2('0','成功',$data, $data2,$data3);exit;	
      
   }
   
   
   
   
   public  function   in_movie(){
       
                  // $mid = I('mid');
                    $shop_no = I('shop_no');
                    $shop_mid = M('shop')->where('id="'.$shop_no.'" AND buss_status =2')->getField('mid');
                    if( $shop_mid ){
                        $mid = $shop_mid;   
                    }else{
                        returnmemberError("1", "店铺号不存在或已被禁用");exit;
                    }

       
                   $shop_id = $this->m->where('mid="'.$mid.'"')->getField('id');
                   $dataInfo = $this->md->where('s_id="'.$shop_id.'"')->find();
                   $data['mid'] = $mid;
                   $data['shop_toppics']  =  $dataInfo['shop_toppics']?__VUPLOAD__.'shop_toppics/'.$dataInfo['shop_toppics']:"";
                   $data['shop_heapic']  =  $dataInfo['shop_heapic']?__VUPLOAD__.'shop_heapic/'.$dataInfo['shop_heapic']:"";
                   $data['shop_name'] = M('shop')->where('mid="'.$mid.'"')->getField('shop_name');
                   $data['shop_intro'] = M('shop')->where('mid="'.$mid.'"')->getField('shop_intro');    
                   $data['address'] = M('shop_detail')->where('s_id="'.$shop_id.'"')->getField('address'); 
                   $data['shop_intropics'] = $dataInfo['shop_intropics'];  
                   $data['per_consumption'] = $dataInfo['per_consumption'];   
                   $data['telephone'] = M('shop_detail')->where('s_id="'.$shop_id.'"')->getField('telephone');  
                  // $data['class_name'] = M('shop_product_class')->where('id="'.$dataInfo['shop_level_three'].'"')->getField('class_name');
                       
                   $attitude = M('shop_evaluate')->where('mid="'.$mid.'"')->sum('attitude_star'); 
                   $speed = M('shop_evaluate')->where('mid="'.$mid.'"')->sum('speed_star'); 
                   $taste = M('shop_evaluate')->where('mid="'.$mid.'"')->sum('taste_star'); 
                   $evaluate_times = M('shop_evaluate')->where('mid="'.$mid.'"')->count();
                   $comment_star = round(( $attitude  + $speed + $taste )/( $evaluate_times*3 ));  
                   $data['comment_star_num'] = $comment_star;
                    
                   if(  $comment_star == 1 ){
                      $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."1star.png";
                   }elseif(   $comment_star == 2  ){
                      $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."2star.png";
                   }elseif(   $comment_star == 3  ){
                      $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."3star.png";
                   }elseif(   $comment_star == 4  ){
                      $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."4star.png";
                   }elseif(   $comment_star == 5  ){
                      $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."5star.png";
                   }else{
                      $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."6star.png";
                   }
                   
                   
//                   
//                  $mid_movie = M('shop_movie')->where('mid="'.$mid.'"')->order('add_time  desc')->select();
//                  foreach ( $mid_movie  as $key => $value){
//                      $data2[$key]['mov_name'] = $value['mov_name'];
//                      $data2[$key]['mov_pic'] = $value['mov_pic']?__VUPLOAD__.'mov_pic/'.$value['mov_pic']:""; //电影头像
//                   }
                  
                   returnApiData2('0','成功',$data, $data2,$data3);exit;	
       
       
   }
 

}